package com.pointi.emoClientM;

import java.util.concurrent.ConcurrentLinkedQueue;

import com.pointi.emoTools.emoLogManager;

public class ThreadStatusChecker extends Thread
{
	ConcurrentLinkedQueue<ThreadStatusChecker> _StatusChecker ;
	JDBC jdbc ;

	CheckStatus _Status ;

	public ThreadStatusChecker(ConcurrentLinkedQueue<ThreadStatusChecker> inStatusChecker)
	{
		_StatusChecker = inStatusChecker ;
	}

	public void start(JDBC inJDBC, CheckStatus inStatus)
	{
		jdbc = inJDBC ;
		_Status = inStatus ;
		_StatusChecker.add(this) ;
		super.start() ;
	}

	public void run()
	{
		try
		{
			boolean loopHandler = true ;
			while (loopHandler)
			{
				emoLogManager.mLog("[StatusChecker] Checking ..") ;
				
				if (_Status.isNewDate()) _Status.fnResetTime() ; // Reset Start Time
				_Status.fnSetRunningTime() ; 
				jdbc.fnUpdateClientStatus(_Status) ; // Update Current Client Status to DB
				
				Thread.sleep(_Status.fnGetCheckInterval()) ;
			}
		}
		catch (Exception e) { e.printStackTrace() ; }
		_StatusChecker.remove(this) ;
	}
}
